package com.just.springboottrans.controller;

import com.just.springboottrans.domain.Person;
import com.just.springboottrans.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PersonController {
    @Autowired
    PersonService personService;
    @PostMapping("/rollback")
    public Person rollback(@RequestBody  Person person){
        return personService.savePersonWithRollback(person);
    }
    @PostMapping("/noRollback")
    public Person moRollback(@RequestBody Person person){
        return personService.savePersonWithoutRollback(person);
    }
    @PostMapping("/save1")
    public Person save1(@RequestBody Person person){
        return personService.save1(person);
    }
    @PostMapping("/save2")
    public Person save2(@RequestBody Person person){
        return personService.save2(person);
    }
    @PostMapping("/save3")
    public Person save3(@RequestBody Person person){
        return personService.save3(person);
    }
    @PostMapping("/save4")
    public Person save4(@RequestBody Person person){
        return personService.save4(person);
    }
    @PostMapping("/save5")
    public Person save5(@RequestBody Person person){
        return personService.save5(person);
    }
    @PostMapping("/t1")
    public Person t1(@RequestBody Person person){
        return personService.testIsolation1(person);
    }
    @PostMapping("/t2")
    public Person t2(@RequestBody Person person){
        return personService.testIsolation2(person);
    }
    @GetMapping("/t3/{id}")
    public Object t3(@PathVariable Long id){
        return personService.testIsolation3(id);
    }
    @PostMapping("/t4")
    public Person t4(@RequestBody Person person){
        return personService.testIsolation4(person);
    }
    @PostMapping("/t5")
    public Person t5(@RequestBody Person person){
        return personService.testIsolation5(person);
    }
    @GetMapping("/find/{id}")
    public Object findOne(@PathVariable Long id){
        Person person=personService.findOne(id);
        return person==null?"fuck":person;
    }

    @PostMapping("/save6")
    public Person save6(@RequestBody Person person){
        return personService.save6(person);
    }
}
